package com.foreveross.taskservice.common.model.airfreight;

import org.apache.commons.lang.math.RandomUtils;
import org.apache.commons.lang3.StringUtils;

import com.foreveross.taskservice.common.CacheDataSpace;
import com.foreveross.taskservice.common.model.AbstractTaskModel;

/**
 * 航空运价任务抓取模型 
 * 这个模型有很多没有用的或者不够用的字段组合，但是为了最大程度的切合抓取引擎那边
 * 先用着，后面需要移植和优化，现在尽量让抓取那边少改代码
 * 
 * @author Administrator
 * 
 */
public class AirFreightTaskModel extends AbstractTaskModel {

	/**
	 * 任务在redis中的key
	 */
	private String taskKey;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -143791787824870388L;

	
	/**
	 * 同一个任务的抓取次数
	 */
	private int grabTimes = 0;
	private String fromCity;
	private String fromCityName;
	private String toCity;
	private String toCityName;
	private String flightDate;
	private String returnGrabDate;
	private String threadName;
	private String remarks;
	private String proxyIp;
	private String attachHbaseKey;
	private int isReturn = 0;
	private int isInternational = 0;
	private String areaCode;
	private String areaName;
	/**
	 * 获取代理ip花费时间
	 */
	private long proxyIpDurationTime = 0L;
	/**
	 * 抓取源网页内容花费时间
	 */
	private long crawlDurationTime = 0L;
	/**
	 * 解析源网页内容花费时间
	 */
	private long parseDurationTime = 0L;
	/**
	 * 存储解析后内容花费时间
	 */
	private long storeDurationTime = 0L;
	/**
	 * 存储在hbase中的源网页数据rowkey值
	 */
	private String sourceRowkey;
	/**
	 * 存储在hbase中的源网页数据的大小
	 */
	private long sourceDataSize = 0;

	public int getGrabTimes() {
		return grabTimes;
	}

	public void setGrabTimes(int grabTimes) {
		this.grabTimes = grabTimes;
	}

	public String getFromCity() {
		return fromCity;
	}

	public void setFromCity(String fromCity) {
		this.fromCity = fromCity;
	}

	public String getFromCityName() {
		return fromCityName;
	}

	public void setFromCityName(String fromCityName) {
		this.fromCityName = fromCityName;
	}

	public String getToCity() {
		return toCity;
	}

	public void setToCity(String toCity) {
		this.toCity = toCity;
	}

	public String getToCityName() {
		return toCityName;
	}

	public void setToCityName(String toCityName) {
		this.toCityName = toCityName;
	}

	public String getFlightDate() {
		return flightDate;
	}

	public void setFlightDate(String flightDate) {
		this.flightDate = flightDate;
	}

	public String getThreadName() {
		return threadName;
	}

	public void setThreadName(String threadName) {
		this.threadName = threadName;
	}

	public String getProxyIp() {
		return proxyIp;
	}

	public void setProxyIp(String proxyIp) {
		this.proxyIp = proxyIp;
	}

	public String getAttachHbaseKey() {
		return attachHbaseKey;
	}

	public void setAttachHbaseKey(String attachHbaseKey) {
		this.attachHbaseKey = attachHbaseKey;
	}

	public int getIsReturn() {
		return isReturn;
	}

	public void setIsReturn(int isReturn) {
		this.isReturn = isReturn;
	}

	public int getIsInternational() {
		return isInternational;
	}

	public void setIsInternational(int isInternational) {
		this.isInternational = isInternational;
	}

	public long getProxyIpDurationTime() {
		return proxyIpDurationTime;
	}

	public void setProxyIpDurationTime(long proxyIpDurationTime) {
		this.proxyIpDurationTime = proxyIpDurationTime;
	}

	public long getCrawlDurationTime() {
		return crawlDurationTime;
	}

	public void setCrawlDurationTime(long crawlDurationTime) {
		this.crawlDurationTime = crawlDurationTime;
	}

	public long getParseDurationTime() {
		return parseDurationTime;
	}

	public void setParseDurationTime(long parseDurationTime) {
		this.parseDurationTime = parseDurationTime;
	}

	public long getStoreDurationTime() {
		return storeDurationTime;
	}

	public void setStoreDurationTime(long storeDurationTime) {
		this.storeDurationTime = storeDurationTime;
	}

	public String getSourceRowkey() {
		return sourceRowkey;
	}

	public void setSourceRowkey(String sourceRowkey) {
		this.sourceRowkey = sourceRowkey;
	}

	public long getSourceDataSize() {
		return sourceDataSize;
	}

	public void setSourceDataSize(long sourceDataSize) {
		this.sourceDataSize = sourceDataSize;
	}

	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	public String getReturnGrabDate() {
		return returnGrabDate;
	}

	public void setReturnGrabDate(String returnGrabDate) {
		this.returnGrabDate = returnGrabDate;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public String getAreaCode() {
		return areaCode;
	}

	public void setAreaCode(String areaCode) {
		this.areaCode = areaCode;
	}

	public String getAreaName() {
		return areaName;
	}

	public void setAreaName(String areaName) {
		this.areaName = areaName;
	}
	
	/**
	 * 重新组装key
	 * @return
	 */
	public String getTaskKey() {
		return new StringBuffer()
		.append(this.getChannel().getHbaseKey())
		.append(this.getStatus()<0?(Math.abs(this.getStatus())<10?"00"+Math.abs(this.getStatus()):"0"+Math.abs(this.getStatus())):(this.getStatus()<10?"10"+this.getStatus():"1"+this.getStatus()))
		.append(this.flightDate.replaceAll("-", ""))
		.append(this.isReturn==1?this.returnGrabDate.replaceAll("-", ""):this.flightDate.replaceAll("-", ""))
		.append(StringUtils.leftPad(String.valueOf(RandomUtils.nextInt(99999999)), 8, '0'))
		.toString();
	}

	public void setTaskKey(String taskKey) {
		this.taskKey = taskKey;
	}

}
